#ifndef VERTEXBUFFER_H
#define VERTEXBUFFER_H

#include "../Utility/Renderer/GeometryTypes.h"
#include "D3D9Renderer.h"

template <typename VertexFormat>
class VertexBuffer
{
    friend class VertexBufferManager;
private:
	IDirect3DVertexDeclaration9	   *m_pVertexDecl;
	IDirect3DVertexBuffer9		   *m_pVertexBuff;

	VertexBuffer();
    VertexBuffer(const VertexBuffer&) {}
    VertexBuffer &operator=(const VertexBuffer&) { return *this; }

	const static int s_VertSizeIncrement = 1000;

	UINT m_NumVerts;
	UINT m_VertsUsed;

	void CreateVertexDeclaration();
    void IncreaseVerts(UINT numVerts);
public:
	~VertexBuffer() 
	{
		if(m_pVertexDecl)
		{
			m_pVertexDecl->Release();
			m_pVertexDecl = 0;
		}
		if(m_pVertexBuff)
		{
			m_pVertexBuff->Release();
			m_pVertexBuff = 0;
		}
	}

	void Initialize();

    UINT AddVerts(const VertexFormat *verts, UINT numVerts);
	void UpdateVerts(const VertexFormat* verts, UINT startVert, UINT numVerts);

	inline IDirect3DVertexDeclaration9 *GetVertexDeclaration() { return m_pVertexDecl; }
	inline IDirect3DVertexBuffer9 *GetVertexBuffer() 
	{ 
		return m_pVertexBuff; 
	}
};

#include "VertexBuffer.hpp"

#endif